﻿#region Copyright
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx
#endregion

#region Imports

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Majesty_of_Omega.Model.Research;

#endregion

namespace Majesty_of_Omega.GUI.Pages.Game.Research.Parts
{
    /// <summary>
    /// Interaction logic for TechMatrixApplicationPart.xaml
    /// </summary>
    public partial class TechMatrixApplicationPart
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TechMatrixApplicationPart"/> class.
        /// </summary>
        public TechMatrixApplicationPart()
        {
            InitializeComponent();
            this.DataContextChanged += TechMatrixApplicationPart_DataContextChanged;
        }

        #region Event Handler

        /// <summary>
        /// Handles the DataContextChanged event of the TechMatrixApplicationPart control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        void TechMatrixApplicationPart_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            TechApplicationStateInfo applicationStateInfo =  (TechApplicationStateInfo) e.NewValue;
            this.ResearchState = applicationStateInfo.ResearchState;
        }

        #endregion

        #region Dependency Property  BorderBackground 

        /// <summary>
        /// Dependency property BorderBackground
        /// </summary>
        public static readonly DependencyProperty BorderBackgroundProperty =
            DependencyProperty.Register("BorderBackground", typeof (Brush), typeof (TechMatrixApplicationPart), new UIPropertyMetadata(null, OnBorderBackgroundValueChanged));


        /// <summary>
        /// Gets or sets the BorderBackground
        /// </summary>
        /// <value>The value.</value>
        public Brush BorderBackground
        {
            get { return (Brush) GetValue(BorderBackgroundProperty); }
            set { SetValue(BorderBackgroundProperty, value); }
        }

        #endregion

        /// <summary>
        /// Change the background of the bordercontrol, when the value of the dependency property BorderBackground
        /// </summary>
        /// <param name="d">instance of TechMatrixApplicationPart</param>
        /// <param name="e">the new and old values</param>
        private static void OnBorderBackgroundValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Brush newValue = (Brush) e.NewValue;
            TechMatrixApplicationPart o = (TechMatrixApplicationPart) d;
            if (o.TechAppBorder != null)
                o.TechAppBorder.Background = newValue;
        }

        #region Dependency Property  ResearchState 

        /// <summary>
        /// Dependency property ResearchState
        /// </summary>
        public static readonly DependencyProperty ResearchStateProperty =
            DependencyProperty.Register("ResearchState", typeof (ResearchState), typeof (TechMatrixApplicationPart), new UIPropertyMetadata(ResearchState.Unknown));

        /// <summary>
        /// Gets or sets the ResearchState
        /// </summary>
        /// <value>The value.</value>
        public ResearchState ResearchState
        {
            get { return (ResearchState) GetValue(ResearchStateProperty); }
            set { SetValue(ResearchStateProperty, value); }
        }
        #endregion
    }
}
